package com.liming.admin.controller;

import com.liming.common.pojo.dto.product.AddCategoryDTO;
import com.liming.common.pojo.dto.product.UpdateCategoryDTO;
import com.liming.common.pojo.vo.product.CategoryTreeVO;
import com.liming.common.pojo.vo.product.CategoryVO;
import com.liming.common.result.LMResult;
import com.liming.product.client.CategoryClient;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author liming
 * @date 2025/1/15
 */
@Slf4j
@RestController
@RequestMapping("/admin/category")
@AllArgsConstructor
@Tag(name = "分类接口-Web")
public class CategoryController {

    private final CategoryClient categoryClient;

    @Operation(
            summary = "分类树",
            responses = {
                    @ApiResponse(responseCode = "1", description = "获取成功", content = {
                            @Content(mediaType = "application/json", schema = @Schema(implementation = CategoryTreeVO.class))
                    })
            }
    )
    @GetMapping
    public LMResult<List<CategoryTreeVO>> tree() {
        return LMResult.success(categoryClient.tree());
    }

    @Operation(
            summary = "详情",
            responses = {
                    @ApiResponse(responseCode = "1", description = "获取成功", content = {
                            @Content(mediaType = "application/json", schema = @Schema(implementation = CategoryVO.class))
                    })
            }
    )
    @GetMapping("{id}")
    public LMResult<CategoryVO> get(@PathVariable Long id) {
        return LMResult.success(categoryClient.get(id));
    }

    @Operation(summary = "新增")
    @PostMapping
    public LMResult<Boolean> add(AddCategoryDTO addCategoryDTO) {
        return LMResult.success(categoryClient.add(addCategoryDTO));
    }

    @Operation(summary = "更新")
    @PutMapping
    public LMResult<Boolean> update(UpdateCategoryDTO updateCategoryDTO) {
        return LMResult.success(categoryClient.update(updateCategoryDTO));
    }

    @Operation(summary = "更新 - 商品精选")
    @PutMapping("selected/{id}")
    public LMResult<Boolean> updateSelected(@PathVariable Long id) {
        return LMResult.success(categoryClient.updateSelected(id));
    }

    @Operation(summary = "删除")
    @DeleteMapping("{id}")
    public LMResult<Boolean> delete(@PathVariable Long id) {
        return LMResult.success(categoryClient.delete(id));
    }

}
